package com.yuntsg.ruiijn.paperana.test;

import com.yuntsg.ruiijn.paperana.entity.*;
import com.yuntsg.ruiijn.paperana.service.ArticleRepeatSummary;
import lombok.SneakyThrows;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.yuntsg.ruiijn.paperana.service.ArticleRepeatSummary.comprehensive;


/**
 * @Author: gcr
 * @Date: 2023/9/20 11:32
 */
public class word {
    @SneakyThrows
    public static void main(String[] args) {

//        String uploadPath = "D:\\";
//        Db use = Db.use();
//        Entity entity = use.queryOne("select * from paper_ana where wos_id = 217635");
//        String str = entity.getStr("result");
//        OutEntity outEntity = JSONObject.parseObject(str, OutEntity.class);
//        PaperAna paperAna = new PaperAna();
//        paperAna.setTitle("1695081207963___论文1(1).pdf");

        String rootPath = "D:\\Users\\55419\\Desktop\\pdfchina\\";


        String afilename = "国自然基金.pdf";
        String bfilename2 = "国自然基金1.pdf";
        List<String> collect = Stream.of(bfilename2).collect(Collectors.toList());
        Double same = 0.6;
        OutEntity out = new OutEntity();
        Map<String, OutEntity.BestArticle> filePdfNameArticleInfo = new HashMap<>();
        Caculate(rootPath, afilename, collect, same, out, filePdfNameArticleInfo);
        System.out.println(out);

//        generateToWord(uploadPath, outEntity, paperAna);
    }


    public static void Caculate(String rootPath, String afileName, List<String> paramBFileNameList, Double threshold, OutEntity outEntity, Map<String, OutEntity.BestArticle> filePdfNameArticleInfo) throws IOException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(format.format(new Date()) + " 程序开始了~~~");
        int size = filePdfNameArticleInfo.size();
        System.out.println("所有论文pmut 全部匹配的文章有效集合是+" + size);
        String directory = rootPath;
        String a = afileName;
        List<String> bFileNameList = paramBFileNameList;
        System.out.println("a文章+" + a);
        System.out.println("b文章集合数量+" + paramBFileNameList.size());
        ArticleRepeatSummary.ComprehensiveInfo comprehensive = comprehensive(directory, a, bFileNameList, threshold);
        double copyProportion = comprehensive.getCopyProportion();
        List<ArticleRepeatSummary.CopyInfo> copyTop5List = comprehensive.getCopyTop5List();
        List<ArticleRepeatSummary.RiskLevelInfo> riskLevelList = comprehensive.getRiskLevelList();
//        System.out.println("总体相似度" + copyProportion);
        List<OutEntity.BestArticle> similarArtLs = new ArrayList<>();
        for (ArticleRepeatSummary.CopyInfo copyInfo : copyTop5List) {
            System.out.println(copyInfo);
            // 最有可能相似的文章 后面word 展示yong
            OutEntity.BestArticle bestArticle1 = filePdfNameArticleInfo.get(copyInfo.getFileName());
            if (bestArticle1 != null) {
                bestArticle1.setSimilarSize(copyInfo.getCopyProportion() + "%");
                similarArtLs.add(bestArticle1);
            } else {
            }

        }
        outEntity.setBestArticles(similarArtLs);
        List<SentenceDiskLevel> sentenceDiskLevel = outEntity.getSentenceDiskLevel();
        for (ArticleRepeatSummary.RiskLevelInfo riskLevel : riskLevelList) {
//            System.out.println(riskLevel.getRiskLevel());
            SentenceDiskLevel sentenceDiskLevel1 = new SentenceDiskLevel();
            if (riskLevel.getRiskLevel().equals(LevelName.HIGHLEVEL)) {
                sentenceDiskLevel1.setLevelName(LevelName.HIGHLEVEL);
            }
            if (riskLevel.getRiskLevel().equals(LevelName.MIDLEVEL)) {
                sentenceDiskLevel1.setLevelName(LevelName.MIDLEVEL);
            }
            if (riskLevel.getRiskLevel().equals(LevelName.LOWLEVEL)) {
                sentenceDiskLevel1.setLevelName(LevelName.LOWLEVEL);
            }
            List<SentenceEntity> ls = sentenceDiskLevel1.getLs();
            List<ArticleRepeatSummary.RiskSentence> sentenceList = riskLevel.getSentenceList();
            for (ArticleRepeatSummary.RiskSentence s : sentenceList) {
                SentenceEntity ins = new SentenceEntity();
                ins.setStr(s.getASentence());
                ins.setMatchStr(s.getBSentence());
                ins.setStrMatchRed(s.getBSentence());
                ins.setStrMatch(s.getBSentence());
                ins.setMaxDoubleMatch(s.getCopyProportion() + "%");
                ins.setMaxDoubleMatchD(s.getCopyProportion());
                OutEntity.BestArticle bestArticle = filePdfNameArticleInfo.get(s.getFileName());
                if (bestArticle != null) {
                    BackMatchEntity match = new BackMatchEntity();
                    match.setType(bestArticle.getType());
                    match.setTitle(bestArticle.getTitle());
                    match.setYear(bestArticle.getYear());
                    match.setAu(bestArticle.getAu());
                    match.setJour(bestArticle.getJour());
                    match.setKey(bestArticle.getKey());
                    match.setDoi(bestArticle.getDoi());
                    ins.setBackMatchEntity(match);
                }


                ls.add(ins);
            }
            sentenceDiskLevel.add(sentenceDiskLevel1);
        }
        outEntity.setSameDouble(copyProportion);
        //校验查看完毕 可以匹配进行适配新版代码 2024年3月28日20:13:51 八点多了 做多少干多少
    }
}
